package com.telecom.service.impl;

import com.telecom.dao.UserDao;
import com.telecom.dao.impl.UserDaoJdbcImpl;
import com.telecom.dao.impl.UserDaoMybatisImpl;
import com.telecom.service.UserService;
import com.telecom.util.PropertiesFactory;
import com.telecom.util.XMLFactory;

import java.util.Optional;

public class UserServiceImpl implements UserService {
    @Override
    public void insert() {
        //硬编码
//        UserDao dao= PropertiesFactory.getBean("dao");//new UserDaoMybatisImpl();//new UserDaoJdbcImpl();
//        dao.save();
        Optional<UserDao> optional = XMLFactory.getBean("dao");
        //如果optional不为空，则执行save方法
        optional.ifPresent(UserDao::save);
    }
}
